import { get, post } from "@/utils/request";
import { parseStrEmpty } from "@/utils/hongke";
const BASE_URL = window.baseUrl
// 查询用户列表
export function listUser(query) {
  return get(BASE_URL + "/system/account/list", query);
}

// 查询用户详细
export function getUser(userId) {
  return get(BASE_URL + "/system/account/detail/" + parseStrEmpty(userId));
}

// 新增用户
export function addUser(data) {
  return post(BASE_URL + "/system/account/add", data);
}

// 修改用户
export function updateUser(data) {
  return post(BASE_URL + "/system/account/update", data);
}

// 删除用户
export function delUser(userId) {
  return post(BASE_URL + "/system/account/delete/" + userId);
}

// 用户密码重置
export function resetUserPwd(userId, password) {
  const data = {
    id: userId,
    password,
  }
  return post(BASE_URL + "/system/account/resetPwd", data);
}

// 用户状态修改
export function changeUserStatus(id, status) {
  const data = {
    id,
    status,
  };

  return post(BASE_URL + "/system/account/changeStatus", data);
}

// 用户状态修改
export function unlockUserStatus(id) {
  return post(BASE_URL + "/system/account/unlock", { id });
}

// 查询用户个人信息
export function getUserProfile() {
  return get(BASE_URL + "/system/account/profile", data);
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return put(BASE_URL + "/system/account/profile", data);
}

// 用户密码修改
export function updateUserPwd(account, oldPwd, newPwd) {
  const data = {
    account,
    oldPassword: oldPwd,
    newPassword: newPwd
  }

  return post(BASE_URL + "/system/account/modifyPwd", data);
}

// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: BASE_URL + "/system/account/profile/avatar",
    method: "post",
    data: data,
  });
}


// 保存授权角色
export function updateAuthRole(userId, roleIds) {
  return post(BASE_URL + "/system/account/authRole/" + userId + "/" + roleIds);
}
// 导入模板下载
export function downloadModel() {
  return post(BASE_URL + "/system/account/importTemplate");
}
// 导入模板
export function importData(data) {
  return post(BASE_URL + '/system/account/importData', data)
}
// 查询所有用户

export function allUser(data) {
  return get(BASE_URL + '/system/user/allUser', data)
}